<?php

session_start();
include_once '../connectBDD.php';
$query = "SELECT * FROM Message where login_receiver ='" . $_SESSION['login'] . "' order by mailing_date_time desc";
$result = mysql_query($query) or die(mysql_error());
echo "<div>
        <span class='btMess'><a href='javascript:ouvrirFenetre(\"nouveauMessage.php\");'>ecrire un message</a></span>
        <span class='btMess'><span class='flecheLocalise'><img src='images/1rightarrow-32.png'/></span><a href='javascript:ajaxBoiteReception();'>boite de reception</a></span>
        <span class='btMess'><a href='javascript:ajaxMsgEnvoyes()'>messages envoyes</a></span>
      </div>";
if (mysql_num_rows($result) <= 0) {
    echo "<div class='no_result_found'>Aucun message</div>";
} else {
    while ($row = mysql_fetch_assoc($result)) {
        $result2 = mysql_query("SELECT login, avatar_path FROM User where login LIKE '%" . $row['login_sender'] . "%'");
        while ($row2 = mysql_fetch_assoc($result2)) {

            $date = date_create($row['mailing_date_time']);
            $date = date_format($date, 'd-m-Y à H:i:s');

            echo"
                         <div id='message_resume'>
                            <div id='petite_image'>
                                <img src=" . $row2['avatar_path'] . " width='50px' height='50px' />
                            </div>
                            <a class='croix_ferm' href=\"javascript:supprimerMess('" . $row['id_msg'] . "', 'recu', '".substr($row['message_content'], 0, 20)."')\"><img src='images/picto_croix.gif'/></a>
                            <div id='blockLoginMP'>
                                <div id='login_msg'>
                                    <a href='profil.php?login=" . $row2['login'] . "'>" . $row2['login'] . "</a>
                                     <span class='heure_msg'>" . $date . "</span>
                                     <a href=\"javascript:ouvrirFenetre('nouveauMessage.php?login=".$row2['login']."')\"><img class='replyImg' src='images/mail_replyall-32.png'/></a>
                                </div>
                                <div id='msg_content'>" . substr($row['message_content'], 0, 100) . "</div>
                            </div>
                        </div>";
        }
    }
}
?>
